package mymyoux.io.sockets.clients.clientsClasses
{
	import mymyoux.utils.Hash;

	public class MSocketsArray
	{
		protected var _sockets:Hash;
		protected var _id:uint;
		public function MSocketsArray(id:uint)
		{
			_sockets = new Hash();
			_id = id;
		}
		public function get first():MBinarySocket
		{
			if(_sockets.length > 0)
			{
				return _sockets.get(_sockets.keys[0]) as MBinarySocket;
			}
			return null;
		}
		public function get(host:String, port:uint):MBinarySocket
		{
			var socket:MBinarySocket;
			if(!_sockets.has(keyMaker(host, port)))
			{
				socket = new MBinarySocket(_id);
				socket.host = host;
				socket.port = port;
				_sockets.put(keyMaker(host, port), socket);
			}else
			{
				socket = _sockets.get(keyMaker(host, port)) as MBinarySocket;
			}
			return socket;
		}
		public function put(host:String, port:uint, socket:MBinarySocket):void
		{
			_sockets.put(keyMaker(host, port), socket);
		}
		protected function keyMaker(host:String, port:uint):String
		{
			return host+":"+port;
		}
	}
}